package com.hzit.auth.controller;


import com.hzit.auth.service.IUserService;
import com.hzit.auth.service.TokenService;
import com.hzit.auth.vo.UserVo;
import com.hzit.entity.LoginUser;
import com.hzit.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;


@RestController
public class LoginController {
	@Autowired
	private IUserService userService;
	@Autowired
	private TokenService tokenService;

	@GetMapping("/login")
	public R login(@RequestBody UserVo vo){
		LoginUser loginUser = userService.findUser(vo);
		if(loginUser != null){
			Map<String,Object> map = tokenService.createToken(loginUser);
			return R.ok(map,"登录成功！");
		}
		return R.fail("登录失败！");
	}
}
